package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.ApartmentInfo;
import com.atguigu.lease.model.entity.FacilityInfo;
import com.atguigu.lease.model.entity.GraphInfo;
import com.atguigu.lease.model.entity.LabelInfo;
import com.atguigu.lease.web.app.mapper.ApartmentInfoMapper;
import com.atguigu.lease.web.app.service.ApartmentInfoService;
import com.atguigu.lease.web.app.vo.apartment.ApartmentDetailVo;
import com.atguigu.lease.web.app.vo.graph.GraphVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author liubo
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {


    @Autowired
    private ApartmentInfoMapper apartmentInfoMapper;

    /***
     *  根据 公寓id 获取公寓其他相关信息
     * @param id
     * @return
     */
    @Override
    public ApartmentDetailVo selectDetailById(Long id) {

        ApartmentDetailVo apartmentDetailVo = new ApartmentDetailVo();

//        根据 公寓id 查询 公寓的基本信息
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(id);
        BeanUtils.copyProperties(apartmentInfo , apartmentDetailVo);
//      1、根据 公寓的id 查询 公寓图片列表
        List<GraphVo> graphVo = apartmentInfoMapper.selectApartmentGraph(id);

//      2、根据公寓的id 查询 标签列表
        List<LabelInfo> labelInfos = apartmentInfoMapper.selectApartmentLabel(id);

//      3、根据 公寓的id 查询公寓的配套
        List<FacilityInfo> facilityInfoList = apartmentInfoMapper.selectApartmentFacility(id);

//      4、根据 公寓的id 查询 租金最小值
        BigDecimal minRent = apartmentInfoMapper.selectApartmentMinRent(id);


        apartmentDetailVo.setGraphVoList(graphVo);
        apartmentDetailVo.setLabelInfoList(labelInfos);
        apartmentDetailVo.setFacilityInfoList(facilityInfoList);
        apartmentDetailVo.setMinRent(minRent);
        return apartmentDetailVo;
    }
}




